home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-04-08 | 33.2 KB | 1,208 lines |
- ------------------------------------------------------------------------------------
-
- RXSOCKET.LIBRARY version 1.6
- MINI-MINI DOC
-
- ------------------------------------------------------------------------------------
-
- LECTURE
-
- THIS SOFTWARE AND INFORMATION ARE PROVIDED "AS IS";
- NO WARRANTIES ARE MADE.
- ALL USE IS AT YOUR OWN RISK, AND NO LIABILITY OR
- RESPONSIBILITY IS ASSUMED.
-
- ------------------------------------------------------------------------------------
-
- INDEX
-
- 1. Introdution
- 2. Installation
- 3. System Requirements
- 4. Author
- 5. Distribution
- 6. Terms
- 7. Bugs
- 8. Structures and value of arguments
- 9. Functions in aplhabetic order
- 10. Thanks
- 11. Bibliography
- 12. To do
- 13. Note
- 14. Last minute
-
- ------------------------------------------------------------------------------------
-
- 1. Introdution
-
- The goal of this library is to offer a set of socket functions to
- arexx-macro.
-
- It makes easy to access the Internet from an arexx macro.
- The functions of this library directly call socket.library functions,
- so this doc does not want to be an introdution to socket.library,
- but just an explanation about the rexx library functions.
-
- The enviroiment is macro-private. Each macro opens the socket.library
- and has a list of "things" that must be freed on exit.
-
- The way used to handle argument or results from function is:
-
- - when the originale socket.library function wants a non-structure
- as argument, that argument is given to the function;
- - when the original socket.library function wants a structure as
- argument, a valid arexx variable name is the argument for that
- struct; various fields of that variable name must be set;
-
- - when the originale socket.library returns an integer, that integer
- is returned;
- - when the originale socket.library returns a structure, a valid arexx
- varable name is passed as argument to the function and various
- fields of that setm are set by the function.
-
- This is a general policy in my rexx library and tries to emulate
- the AmigaOS tags programming way.
-
-
- The library offers quite all the bsdsocket.library functions,
- and some other function of a higher level (hehe just a couple
- for now). The function dos not directly support raw packet, or
- protocolls different from tcp, udp, but creating a memory
- block and filling it by hands makes use of raw packets possible.
-
-
- ------------------------------------------------------------------------------------
-
- 2. Installation
-
- No installation script is given.
-
- To install the library:
- - copy rxsocket.library to libs:
- - write in a shell:
- rx "call addlib('rxsocket.library',0,-30)
-
- ------------------------------------------------------------------------------------
-
- 3. System Requirements
-
- The library needs AmigaOS>2.
- The library is tested on miami.
- It should work on AmiTCP.
- It should work on termiteTCP ver 1.50, but same functions
- are not avaible.
-
- ------------------------------------------------------------------------------------
-
- 4. Author
-
- Alfonso Ranieri
-
- E-Mail: alfier@iol.it
-
- You can find alfie (hiu, theQ) at:
- - dalnet #amichat
- - ircnet #amigaita
- - ircnet #amyita
-
- ------------------------------------------------------------------------------------
-
- 5. Distribution
-
- rxsocket.library is FreeWare.
-
- You are free to detribute it as long as the original archive is
- kept intact. Commercial use or its inclusion in other software
- package is prohibited without prior consens from the Author.
-
- ------------------------------------------------------------------------------------
-
- 6. Terms
-
- In this doc same terms need explanation:
-
- - stemName a valid arexx variable name
- i.e. var, var.0, var.name, var
-
- - socket the socket numeric value returned from
- socket(), ObtainSocket()
-
- - addr the integer arexx number returned from resolve() inet_addr()
- and in various stem fileds. It is the u_long internet address you
- use as argument for various functions. Don't make any assumption
- on its value, because this is an arexx signed integer rather than
- a c u_long, just compare it to -1 to know if it is bad.
-
- - types of arguments the type used are:
- D any data none
- N numeric /N
- S symbol /S arexx valid symbol
- V stemName /V arexx valid symbol as S but with length<20
-
- ------------------------------------------------------------------------------------
-
- 7. Bugs
-
- There are bugs in our wonderfull kernel.
- There are bugs in very expansive commerciale products.
-
- Why shouldn't they be here?
-
- This is just quite a beta version, tested, but not so much.
-
- There is actually a well known problems:
-
- - on miami after a ReleaseSocket()/ObtainSocket() if the socket
- obtained is passed to connect() an enforcer hit cames out.
- This is a problem of miami, not mine.
-
- If you find bugs (and i am sure you'll do) write me asap, please.
-
- ------------------------------------------------------------------------------------
-
- 8. Structures and value of arguments passed or returned
-
- Actually 4 structures are passed or returned to/from functions.
- They are the socket.library structures:
- - struct hostent returned by gethostbyname()
- - struct servent returned by getservbyname(), getservbynumber()
- - struct protoent returned by getprotobyname(), getprotobynumber()
- - struct sockaddr_in passed and returned to/from various functions
-
- As i said above, i emulate structure as arexx stemName;
- an example will help:
-
- we want to get the local protoent of the echo tcp service
- so we need a call to getservbyname() passing it a stemName (see Terms)
-
- ---------------
-
- if ~getservbyname("SE","echo","tcp") then do
- /* failure */
- say "no echo tcp service"
- exit
- end
-
- /* success */
- say "Name:" se.SERVNAME
- say "Port:" se.SERVSPORT
- say "Proto:" se.SERVPROTO
-
- if se.SERVALIASES.num=0 then say "No alias"
- else do
- say "Alisases"
- do i = 0 to se.SERVALIASES.num-1
- say se.SERVALIASES.i
- end
- end
-
- ---------------
-
- As you can see, getservbyname() fells on success the fields
-
- - SERVNAME
- - SERVPORT
- - SERVPROTO
- - SERVALIASES.NUM
- - SERVALIASES.0 , ... , SERVALIASES.last ( last = SERVALIASES.NUM-1 )
-
- of the arexx stem that has as root part that stemName you give the
- function as first arguments.
-
- If an array is part of the structure then the number of members
- are returned in X.Y.NUM and the mebers can be found in
- X.Y.0 , .... , X.Y.last last = X.Y.NUM -1 ;
- so if X.Y.NUM == 0 the array is empty.
-
- For each structure the fields read or write by functions are:
-
- - hostent
- - HOSTNAME
- - HOSTADDRTYPE
- - HOSTLENGTH
- - HOSTALIASES.NUM
- - HOSTALIASES.0 , ... , HOSTALIASES.last ( last = HOSTALIASES.NUM-1 )
- - HOSTADDRLIST.NUM
- - HOSTADDRLIST.0 , ... , HOSTADDRLIST.last ( last = HOSTADDRLIST.NUM-1 )
-
-
- - servent
- - SERVNAME
- - SPORT
- - SERVPROTO
- - SERVALIASES.NUM
- - SERVALIASES.0 , ... , SERVALIASES.last ( last = SERVALIASES.NUM-1 )
-
- - protoent
- - PROTONAME
- - PROTOPROTO
- - PROTOALIASES.NUM
- - PROTOALIASES.0 , ... , PROTOALIASES.last ( last = PROTOALIASES.NUM-1 )
-
- - struct sockaddr_in
- passed as argument to functions
- - ADDRFAMILY
- - ADDRPORT
- - ADDRADDR
-
- returned from functions
- - ADDRLEN
- - ADDRFAMILY
- - ADDRPORT
- - ADDRADDR
-
- To make life easier a lots of arguments have their human form and
- can be passed to functions (directly or in as stem field)
- as string.
- They are expecially:
-
- - FAMILY as in socket(family,type,protocol) or ADDRFAMILY
- the internet family that actually has just the string form
- "INET" and MUST BE THAT STRING IN THIS VERSION OF THE LIBRAY!
-
- can be passed as integer too.
-
- - type as in socket(family,type,protocol)
- the type of the socket has the string forms
- "STREAM"
- "DGRAM"
- "RAW"
- "RDM"
- "SEQPACKET"
-
- can be passed as integer too.
-
- - protocoll as in socket(family,type,protocol)
- the protocol of the socket has the string forms
- "IP"
- "HOPOPTS"
- "ICMP"
- "IGMP"
- "GGP"
- "IPIP"
- "TCP"
- "EGP"
- "PUP"
- "UDP"
- "IDP"
- "TP"
- "IPV6"
- "ROUTING"
- "FRAGMENT"
- "RSVP"
- "ESP"
- "AH"
- "ICMPV6"
- "NONE"
- "DSTOPTS"
- "EON"
- "ENCAP"
- "DIVERT"
- "RAW"
-
- can be passed as integer too.
-
- Hehe just few protocoll will work in this version of the libray, but ...
- if you are pretty good in TCP/IP programming you can get same mem
- in arexx, create your own packet, i.e. an icmp packet, filling
- the right values for ip header and icmp header , open a row socket
- setsockopt() socket as IP_HDRINCL and send your own packet :-)))
- Maybe in future versions, general packet creation will be performed.
-
- ------------------------------------------------------------------------------------
-
- 9. Functions in aplhabetic order:
-
- THIS IS NOT A DOC ABOUT SOCKET FUNCTIONS AT ALL
- REFER TO GOOD SOCKET FUNCTIONS BOOKS OR TO SOCKET.LIBRARY AUTODOC
- FOR USE, ARGUMENTS AND RESULTS OF THESE FUNCTIONS
-
- ------------------------------------------------------------------------------------
-
- ACCEPT()
- Usage: ACCEPT(socket,stem)
- <socket/N>,<stem/V>
-
- Accepts a connection on socket after a a bind() and listen().
- Create and returns a new socket for the connection.
- Fills stem with sockaddr_in fields.
-
- The function returns -1 for failure. Errno() can be used to get
- the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- ADDR2C
- Usage: ADDR2C(addr)
- <addr/N>
-
- Converts an Internet address - like from resolve - to packed chars.
- Usefull when you have to export and address into memory.
-
- ------------------------------------------------------------------------------------
-
- BIND()
- Usage: BIND(socket,stem)
- <socket/N>,<stem/S>
-
- Tries to "bind" the socket.
- "stem" must have set then fields:
- - ADDRFAMILY only "INET" for now;
- - ADDRADDR is an integer indicating the inet addr, i.e. as returned by inet_addr()
- - ADDRPORT is the port you want the socket bind to.
-
- The function returns -1 for failure. Errno() can be used to get
- the error code for failure.
-
- EXAMPLE
-
- sock = socket("INET","DGRAM","IP")
- if sock<0 then do
- say "cannot open socket:" Errno()
- exit
- end
-
- local.ADDRFAMILY = "INET"
- local.ADDRADDR = 0
- local.ADDRPORT = 4000
-
- if bind(sock,"LOCAL")<0 then do
- say "cannot allocate port 4000:" Errno()
- exit
- end
-
- ------------------------------------------------------------------------------------
-
- CLOSESOCKET
- Usage CLOSESOCKET(socket)
- <socket/N>
-
- Closes a socket. "socket" is an integer socketfd returned by socket().
-
- The function returns -1 for failure. Errno() can be used to
- get the error code for failure.
-
- THE SOCKETFD CANNOT BE USED AFTER A CALL TO THIS FUNTION.
- INTERNAL RESORCE ARE NOMORE AVAIBLE.
-
- ------------------------------------------------------------------------------------
-
- CONNECT
- Usage CONNECT(socket,stem)
- <socket/N>,<stem/S>
-
- Connects the "socket" to the socketaddr as defined in "stem".
-
- "socket" is an integer socketfd returned by socket(),
- "stem" is a valid arexx name, with the fields ADDRFAMILY, ADDRADDR, ADDRPORT
- set:
- - ADDRFAMILY can be just "INET" for now;
- - ADDRADDR is an integer indicating the inet addr, i.e. as returned by inet_addr()
- - ADDRPORT the port you want to connect to
-
- The function returns -1 for failure. Errno() can be used to get
- the error code for failure.
-
- EXAMPLE
-
- sin.addrfamily = "INET"
- sin.addrport = se.SERVPORT /* from a call to getservbyname() */
- sin.addraddr = he.HOSTADDRLIST.0 /* from a call to getshotbyname () */
-
- if connect(sockfd,"SIN")<0 then do
- say "connect: error" Errno()
- exit
- end
-
- ------------------------------------------------------------------------------------
-
- DUP2SOCKET
- Usage: DUP2SOCKET(socket)
- <socket/N>
-
- Duplicates an existing socket descriptor and returns its
- value. A new macro internal socket resource is allocated.
- Returns the new socketfd on success.
- It calls the original dup2socket() function with the second
- argument as -1.
-
- The function returns 1 fo succes, 0 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- ERRNO
- Usage ERRNO()
-
- Returns the current error code.
-
- ------------------------------------------------------------------------------------
-
- ERRORSTRING
- Usage: ERRORSTRING(code)
- <code/N>
-
- Returns the error string associated with the error code.
-
- ------------------------------------------------------------------------------------
-
- GETHOSTBYADDR
- Usage: GETHOSTBYADDR(stem,addr)
- <stem/V>,<addr/N>
-
- Fills "stem" by host data, host pointed by "addr".
- "stem" is a valid arexx name, "arexx" is an integer inet addr, i.e. as
- returned bye inet_addr(), "len" is the address length, "type" is the
- address type.
-
- The following fields of stem are set:
- - HOSTNAME official name of the host
- - HOSTADDRTYPE the type of address being returned;
- - HOSTLENGTH the length, in bytes, of the address.
- - HOSTALIASES.NUM the number of alternate names for the host, the name of which
- are in HOSTALIASES.0,... HOSTALIASES.i (i=HOSTALIASES.NUM-1)
- - HOSTADDRLIST.NUM the number of network addresses, which are in
- HOSTADDRLIST.0,... HOSTADDRLIST.i (i=HOSTALIASES.NUM-1) as integer.
-
- The function returns 1 fo succes, 0 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- GETHOSTBYNAME
- Usage: GETHOSTBYNAME(stem,hostName)
- <stem/V>,<hostName>
-
- Fills "stem" by host data, host pointed by "hostName".
- "stem" is a valid arexx name, "arexx" is an integer inet addr, i.e. as
- returned bye inet_addr(), "len" is the address length, "type" is the
- address type.
-
- The following fields of stem are set:
- - HOSTNAME official name of the host
- - HOSTADDRTYPE the type of address being returned; currently always INET.
- - HOSTLENGTH the length, in bytes, of the address.
- - HOSTALIASES.NUM the number of alternate names for the host, the name of which
- are in HALIASIS.0,... HOSTALIASES.i (i=HOSTALIASES.NUM-1)
- - HOSTADDRLIST.NUM the number of network addresses, which are in
- HOSTADDRLIST.0,... HOSTADDRLIST.i (i=HOSTALIASES.NUM-1) as integer.
-
- The function returns 1 fo succes, 0 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- GETHOSTID
- Usage: GETHOSTID()
-
- Returns the unique identifier of current host.
-
- ------------------------------------------------------------------------------------
-
- GETHOSTNAME
- Usage: GETHOSTNAME(stem)
- <stem/V>
- Fills stem with the current host name. Returns an arex boolean.
-
- ------------------------------------------------------------------------------------
-
- GETPEERNAME
- Usage: GETPEERNAME(socket,stem)
- <socket/n>,<stem/V>
-
- Returns the name of the peer connected to socket "socket".
-
- The following fields of stem are set:
- - ADDRLEN the length, in bytes, of the address
- - ADDRFAMILY family
- - ADDRPORT the port number
- - ADDRADDR the addr as integer
-
- The function returns 1 fo succes, 0 for failure.
- Errno() can be used to get the error code for failure.
-
- NO TermiteTCP
-
- ------------------------------------------------------------------------------------
-
- GETPROTOBYNAME
- Usage: GETPROTOBYNAME(stem,proto)
- "<stem/V>,<protocol>"
-
- Returns local protocol data in stem, from protocol name.
-
- The following fields of stem are set:
- - PROTONAME name of the protocol
- - PROTOPROTO id of protocol
- - PROTOALIASES.NUM the number of alternate names for the protocol, the name of which
- are in PALIASIS.0,... PROTOALIASES.i (i=PROTOALIASES.NUM-1)
-
- The function returns 1 fo succes, 0 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- GETPROTOBYNUMBER
- Usage: GETPROTOBYNUMER(stem,protocol)
- "<stem/V>,<protocol/N>"
-
- Returns local protocol data in stem, from protocol id number.
-
- The following fields of stem are set:
- - PNAME name of the protocol
- - PROTOPROTO id of protocol
- - PROTOALIASES.NUM the number of alternate names for the protocol, the name of which
- are in PALIASIS.0,... PROTOALIASES.i (i=PROTOALIASES.NUM-1)
-
- The function returns 1 fo succes, 0 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- GETSERVBYNAME
- Usage: GETSERVBYNAME(stem,hostName,proto)
- <stem/V>,<name>,[proto]
-
- Fills "stem" with the datas of the broken-out fields of an
- entry in the local network services data base, from the name of the service.
-
- The following fields of stem are set:
- - SERVNAME the official name of the service
- - SERVPORT the port number at which the service resides
- - SERVPROTO the name of the protocol to use when contacting the service
- - SERVALIASES.NUM the number of the alternate names for the service,
- the name of which are in SERVALIASES.0,... SERVALIASES.i (i=SERVALIASES.NUM-1)
-
- The function returns 1 fo succes, 0 for failure.
- Errno() can be used to get the error code for failure.
-
- NO TermiteTCP
-
- ------------------------------------------------------------------------------------
-
- GETSERVBYPORT
- Usage: GETSERVBYPORT(stem,hostName,proto)
- <stem/V>,<port/N>,[proto]
-
- Fills "stem" with the datas of the broken-out fields of an
- entry in the local network services data base, from the port of the service.
-
- The following fields of stem are set:
- - SERVNAME the official name of the service
- - SERVPORT the port number at which the service resides
- - SERVPROTO the name of the protocol to use when contacting the service
- - SERVALIASES.NUM the number of the alternate names for the service,
- the name of which are in ALIASES.0,... ALIASES.i (i=ALIASES.NUM-1)
-
- The function returns 1 fo succes, 0 for failure.
- Errno() can be used to get the error code for failure.
-
- NO TermiteTCP
-
- ------------------------------------------------------------------------------------
-
- GETSOCKETBASE
- Usage: GETSOCKETBASE(stem)
- <stem/V>
-
- Gets global parameter in the protocol stack.
- The original bdsocket.library function is SocketBaseTagList, which is
- used to get/set; here we split it in 2 as GETSOCKETBASETAGLIST() and
- SETSOCKETBASETAGLIST().
-
- You must set the field of "stem" you want to read, then call the function.
- The function fills the amy field you set with its current value.
-
- The fields accepted are:
- - BREAKMASK
- - DTABLESIZE
- - ERRNO
- - ERRNOSTRPTR
- - HERRNOSTRPTR
- - HERRNO
- - LOGMASK
- - LOGSTAT
- - LOGTAGPTR
-
- (Take a look at socket.library/SocketBaseTagList)
-
- The function return -1 for failure. Errno() can be used to get the error code
- for failure.
-
- EXAMPLE
-
- drop a. /* to be sure we don't make a mass :-) */
-
- a.ERRNOSTRPTR=40 /* must be numeric */
- a.BREAKMASK=1 /* can be whatever you want */
- a.HERRNOSTRPTR=2 /* must be numeric */
-
- call GetSocketBaseTagList("A")
-
- say a.ERRNOSTRPTR ----->Message too long
- say a.BREAKMASK ----->4096
- say a.HERRNOSTRPTR ----->Host name lookup failure
-
-
- ------------------------------------------------------------------------------------
-
- GETSOCKETEVENTS
- Usage: GETSOCKETEVENTS(name,opt,stem)
- <name/V>,<opt>,<stem/V>
-
- Gets asynchronous socket events. You give to it a name, and
- it fill stem the value of "opt"; valid opts are:
- - ACCEPT
- - CLOSE
- - CONNECT
- - ERROR
- - OOB
- - READ
- - WRITE
-
- Return the socket number or -1.
- Errno() CAN'T be user afeter this function.
-
- ------------------------------------------------------------------------------------
-
- GETSOCKETNAME
- Usage: GETSOCKETNAME(socket,stem)
- <socket/N>,<stem/V>
-
- Returns the current name for the specified socket, filling the fields:
- - ADDRLEN
- - ADDRFAMILY
- - ADDRADDR
- - ADDRPORT
-
- Return -1 for failure.
-
- ------------------------------------------------------------------------------------
-
- GETSOCKOPT
- Usage GETSOCKOPT(socket,level,name,stem)
- <socket/N>,<level>,<name>,<stem/V>
-
- Fills stem with value of the opt name associated with
- a socket at level "level".
-
- For now levels are:
-
- -SOCKET
- -IP
-
- Valid opt for SOCKET are:
- - DEBUG
- - REUSEADDR
- - REUSEPORT
- - KEEPALIVE
- - DONTROUTE
- - LINGER
- - BROADCAST
- - OOBINLINE
- - TYPE
- - ERROR
-
- The value is written in stem.
- If LINGER, the fields ONOFF, LINGER of stem are filled.
-
- Valid opt for IP are
- - HDRINCL
- - IPOPTIONS just returns a boolean not a buffer!!!
- - TTL
- - TOS
-
- The function returns -1 for failure. Errno() can be used to get the error code
- for failure.
-
- ------------------------------------------------------------------------------------
-
- HELP
- Usage: HELP(funName)
- <funName>
-
- Returns the arguments string of "funName".
- This is a "help function" that all my arexx library offer.
-
- ------------------------------------------------------------------------------------
-
- INETADDR
- Usage: INETADDR(addr)
- <addr/N>
-
- Converts IP address from text to integer form.
- Returns -1 on error.
-
- ------------------------------------------------------------------------------------
-
- INETNTOA
- Usage: INETNTOA(hostName)
- <addr>
-
- Converts IP address from integer to text form.
-
- ------------------------------------------------------------------------------------
-
- IOCTLSOCKET
- Usage: IOCTLSOCKET(socket,req,value)
- <socket/N>,<req>,<value/n>
-
- Controls "socket" parameters.
-
- Actual req value are:
- - FIOASYNC
- - FIONBIO
- - FIONREAD
- - SIOCATMARK
- (Take a look at bsdsocket.library/IoctlSocket)
-
- The function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- LISTEN
- Usage: LISTEN(socket,backlog)
- <socket/N>,<backlog/n>
-
- Listens for connections on a socket.
-
- The function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- ISLIBON
- Usage: ISLIBON(name)
- <name>
-
- Tests on what stack the library is working on or if a library is present,
- returning a boolean.
-
- Value for name are:
-
- - MIAMI running on miami
- - TTCP running on tcp
- - USERGROUP (not yet usefull)
-
- ------------------------------------------------------------------------------------
-
- OBTAINSOCKET
- Usage: OBTAINSOCKET(key,socket,family,type,protocol)
- <key/N>,<family>,<type>,[protocol]
-
- Obtains a previously released socket.
- Only arexx macro released socket can be obtained.
-
- ------------------------------------------------------------------------------------
-
- OPENCONNECTION
- Usage: OPENCONNECTION(proto,port,host,remotePort,stem)
- <proto>,<localport>,[host],[remoteport],[stem/V]
-
- Let's see the different forms:
-
- proto can be the string "tcp" or "udp".
-
- res=OpenConnection(proto,4050)
- create a socket
- bind the socket to port 4050
-
- res=OpenConnection(proto,"funnyService")
- serach for a local serv entry with the name "funnyService"
- create a socket INET STREAM TCP or INET DGRAM UDP
- bind the socket on the service port
-
- res=OpenConnection("tcp","echo","www.nasa.org")
- create a socket INET STREAM TCP
- search for a local serv entry with the name "echo"
- connect the socket to www.nasa.org:echo
-
- res=OpenConnection("udp","echo","www.nasa.org")
- ERROR
-
- res=OpenConnection("tcp",4000,"www.nasa.org")
- ERROR
-
- res=OpenConnection("tcp",4000,"www.nasa.org","echo")
- create a socket INET DGRAM UDP
- bind the socket to port 4000
- search for a local serv entry with the name "echo"
- connect the socket to www.nasa.org:echo
-
- Did you understand?
-
- Take a look at the examples.
- Read same docs for the differeces beetwen conneting a socket
- of type tcp or udp.
-
- Have fun!
-
- The function returns:
- -3 server entry serch failure
- -2 host lookup failure
- -1 bsdsocket.library error
- >=0 socket number id
-
- If present as the 5th argument and on connection, stem
- is filled as socketaddr_in.
-
- NO TermiteTCP
-
- ------------------------------------------------------------------------------------
-
- RECV
- Usage: RECV(socket,stem,len,flags)
- <socket/N>,<stem/V>,<len/n>,[flags/n]
-
- Receives data from "socket". It receives max "len" data and fills "stem"
- with the data received.
-
- The function returns -1 for failure or data length read.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- RECVFROM
- Usage: RECVFROM(socket,bufStem,len,flags,stem)
- <socket/N>,<stem/V>,<len/n>,[flags/n],[stem/V]
-
- Receives data from "socket". I receives max "len" data and fills "bufStem"
- with the data received.
-
- if present, "socketStem" is a valid arexx name, with the fields ADDRFAMILY,
- ADDRADDR, ADDRPORT set:
- - ADDRFAMILY can be just "INET" for now;
- - ADDRADDR is an integer indicating the inet addr, i.e. as returned by inet_addr()
- - ADDRPORT is the "well known" port you want to connect
- and it is filled back.
-
- If sock is connected
-
- recvfrom(sock,buff,len)
- recvfrom(sock,buff,len,,)
- recv(sock,buff,len)
-
- are the same things
-
- The function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- RECVLINE
- Usage: RECVLINE(socket,bufStem,len,stem,flags)
- "<socket/N>,<stem>,<len/n>,[flags/N],<stem>
-
- Receives a line from "socket". I receives max "len" data and fills "bufStem"
- with the data received.
-
- if present, "socketStem" is a valid arexx name, with the fields ADDRFAMILY, ADDRADDR,
- ADDRPORT set:
- - ADDRFAMILY can be just "INET" for now;
- - ADDRADDR is an integer indicating the inet addr, i.e. as returned by inet_addr()
- - ADDRPORT is the "well known" port you want to connect
- and it is filled back.
-
-
- The function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- This is a relly bad non buffered readline. Don't use it so much!
-
- ------------------------------------------------------------------------------------
-
- RELEASECOPYOFSOCKET
- Usage: RELEASECOPYOFSOCKET(socket)
- <socket/N>
-
- Releases a copy of a socket to the public.
- The function returns a key string to be used with ObtainSocket().
- Don't mess with that key or try to pass ObtainSocket() any other value!
- The original socket is still active and private in the macro.
- See note in Bugs.
-
- The function return a Null() on failure.
-
- ------------------------------------------------------------------------------------
-
- RELEASESOCKET
- Usage: RELEASESOCKET(socket)
- <socket/N>
-
- Releases a socket to the public.
- The function returns a key string to be used with ObtainSocket().
- Don't mess with that key or try to pass ObtainSocket() any other value!
- The socket is no more active but still in the caller the macro environment.
-
- If the socket is not released, it belongs to the caller macro still.
-
- The function return a Null() on failure.
-
- EXAMPLE
- key = ReleaseSocket(sock)
- if key == Null() then /* failure */
-
- ------------------------------------------------------------------------------------
-
- RESOLVE
- Usage: RESOLVE(host)
- <host>
-
- Converts IP address from text or name form to integer.
- The functions try first a inet_addr() and then a gethosbyname().
- Returns -1 or address of host.
-
- ------------------------------------------------------------------------------------
-
- SEND
- Usage: SEND(socket,data,flags)
- <socket/N>,<data>,[flags/N]
-
- Sends data to a connected "socket".
-
- The function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- SENDTO
- Usage: SENDTO(socket,data,flags,stem)
- <socket/N>,<data>,[flags/n],[stem/V]
-
- Send data to "socket".
-
- If present "stem" is a valid arexx name, with the fields ADDRFAMILY, ADDRADDR,
- ADDRPORT set:
- - ADDRFAMILY can be just "INET" for now;
- - ADDRADDR is an integer indicating the inet addr, i.e. as returned by inet_addr()
- - ADDRPORT is the "well known" port you want to connect
-
- The function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- SETSOCKETBASE
- Usage: SETSOCKETBASE(stem)
- <stem/V>
-
- Sets global parameter in the protocol stack.
- The original bdsocket.library function is SocketBaseTagList, which is
- use to get/set; here we split it in 2 as GETSOCKETBASETAGLIST() and
- SETSOCKETBASETAGLIST().
-
- You must set the field of "stem" with the value you want to set,
- then call the function.
- The fields accepted are:
- - BREAKMASK
- - DTABLESIZE
- - ERRNO
- - HERRNO
- - LOGMASK
- - LOGSTAT
- - LOGTAGPTR
- (Take a look at socket.library/SocketBaseTagList)
-
- The function returns -1 for failure. Errno() can be used to get the error code
- for failure.
-
- ------------------------------------------------------------------------------------
-
- SETSOCKOPT
- Usage SETSOCKOPT(socket,level,opt,value,value)
- <socket/N>,<level>,<opt>,[value],{value/N}
-
- Set value of the opt name associated with a socket at level "level".
-
- For now levels are:
-
- SOCKET
- IP
- TCP
-
- Valid opt for level SOCKET are:
- - DEBUG N
- - REUSEADDR N
- - REUSEPORT N
- - KEEPALIVE N
- - DONTROUTE N
- - LINGER N
- - BROADCAST N
- - OOBINLINE N
- - SNDBUF N
- - RCVBUF N
- - SNDLOWAT N
- - RCVLOWAT N
- - SNDTIMEO N
- - RCVTIMEO N
- - EVENTMASK D (see GETSOCKETEVENTS)
-
- If opt is SO_LINGER, SO_SNDTIMEO or SO_RCVTIMEO the 3rd argument can be passed
- (default 0).
-
- Valid opt for level IP are:
- - HDRINCL N
- - TTL N
- - TOS N
-
- Valid opt for level TCP are:
- -NODELAY N
- -MAXSEG N
- -NOPUSH N
- -NOOPT N
-
- Thes function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- SHUTDOWN
- Usage: SHUTDOWN(socket,how)
- <socket/N>,<how/N>
-
- Causes all or part of a full-duplex connection on
- the socket associated with s to be shut down. If how is 0, further
- receives will be disallowed. If how is 1, further sends will be
- disallowed. If how is 2, further sends and receives will be
- disallowed.
-
- The function return -1 for failure. Errno() can be used to get the error code
- for failure.
-
- THE SOCKETFD CANNOT BE USED AFTER THIS FUNTION. INTERNAL RESORCE ARE NOMORE AVAIBLE.
-
- ------------------------------------------------------------------------------------
-
- SOCKET
- Usage: SOCKET(family,type,protocol)
- <family>,<type>,<protocol>
-
- Creates an endpoint for communication and returns a descriptor.
- It also adds to the local-macro list of open sockets a new link so that
- resource can be freed at macro exit.
-
- It returns a socketfd as integer that must be used in every function
- wich needs a "socket" argument.
-
- The function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- WAITSELECT
- Usage: WAITSELECT(stem,secs,micro,signals)
- <stem>,[secs/N],[micro/N],[signals/N]
-
- Waits for events on sockets, time, exec signals.
-
- An example will help.
-
- Let's suppose we have 2 sockets, sf1 and sf2, and we want to controll
- if something happens about that. We do:
-
- WAIT.READ.0 = sfd1 /* to wait for ready to be read event */
- WAIT.READ.1 = sfd2
-
- WAIT.WRITE.0 = sfd1 /* to wait for ready to be written event */
- WAIT.WRITE.1 = sfd1
-
- WAIT.EX.0 = sfd1 /* to wait for exceptions event */
- WAIT.EX.1 = sfd2
-
- /* we wait for the events above, or 10 seconds or a signal in sig mask */
- res = WaitSelect("WAIT",10,0,sig)
-
- /* res may be:
- < 0 -> error
- = 0 no events on sockets
- > 0 number of ready sockets
-
- To test wich sockets is ready we make a boolean test on WAIT.0.READ
- and so on */
-
- if WAIT.0.READ then ... /* socket sfd1 is ready to be read */
- ...
-
- The function returns -1 for failure.
- Errno() can be used to get the error code for failure.
-
- ------------------------------------------------------------------------------------
-
- 10. Thanks
-
- - thanks to shido for his gift "hi shido you are so great!"
-
- - thanks to [X_MaN] who introduced me into the irc world
- and Internet in general
-
- - thanks to "Unix Network Programming"
-
- - thanks to Kruse for his wonderfull miami ( "hey man i really
- hope those rumours about backdoors are not true at all")
-
- - thans to poing for his help
-
- - thans to Amiga "may it leave for ever!"
-
- ------------------------------------------------------------------------------------
-
- 11. Bibliography
-
- - Quite all rfc
-
- - "Unix Network Programming" - W. Richard Stevens PTR Prentice Hall
-
- - socket.library autodoc
-
- ------------------------------------------------------------------------------------
-
- 12. To do
-
- Very much:
-
- - first of all a serious debugging :-)
-
- - init_inetd() function
-
- - hehe a pretty good reacvline()
-
- - direct creation of raw packets, icpm packet and so on.
-
- - miami.library functions
-
- - higher lever functions
-
- ------------------------------------------------------------------------------------
-
- 13. Note
-
- Function to deallocate the local enviroiment in the library base
- is saved in the fields pr_ExitCode and pr_ExitData of the Process
- structure of the macro.
- At the exit a chain of pr_ExitCode(pr_ExitData) is called.
-
- The problem is with the inetd that passes copy of the release
- socket just there, hehe.
-
- ------------------------------------------------------------------------------------
-
- 14. Last minute
-
- Some functions have been added (they are in another library, i don't
- want to make pubblic yet). They are:
-
- NAME description args
- ------------------------------------------------------------------------------------
- ALLOCSIGNAL alloc and retur a signal byte no args
- * FREESIGNAL free an allocated signal byte <signal/N>
- OR or till 15 long {signal/N}
- AND and till 15 long {signal/N}
- PORTSIGNAL return byte signal of a
- local OPENPORT() port <portName>
- WAIT wait for signals or secs,micro <signals/N>,[sec/N],[micro/N]
- * SIGNAL signal a process "<task/N>,<signals/N>"
- ------------------------------------------------------------------------------------
-
- THE * MEANS THE FUNCTION CAN BE DANGEROUS
-